package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.ProductSpecService;
import com.atguigu.spzx.model.entity.product.ProductSpec;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/product/productSpec")
@Tag(name = "商品规格管理模块")
public class ProductSpecController {
    @Autowired
    private ProductSpecService productSpecService;

    @GetMapping("/{current}/{size}")
    @Operation(summary = "分页带条件查询商品规格信息")
    public Result<PageInfo<ProductSpec>> findProductSpecByPage(@PathVariable Integer current,@PathVariable Integer size){
        PageInfo<ProductSpec> list=productSpecService.findProductSpecByPage(current,size);
     return Result.build(list, ResultCodeEnum.SUCCESS);
    }

    @PostMapping("save")
    @Operation(summary = "增加商品规格信息")
    public Result save(@RequestBody ProductSpec productSpec){
        productSpecService.save(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("保存成功");
    }
    @PutMapping("updateById")
    @Operation(summary = "修改商品规格信息")
    public Result updateById(@RequestBody ProductSpec productSpec){
        productSpecService.updateById(productSpec);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("修改成功");
    }
    @DeleteMapping("deleteById/{id}")
    @Operation(summary = "根据id删除商品规格信息")
    public Result deleteById(@PathVariable Long id){
        productSpecService.deleteById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS).setMsg("删除成功");
    }

    @GetMapping("findAll")
    @Operation(summary = "查询所有商品规格")
    public Result<List<ProductSpec>> FindAllProductSpec(){
      List<ProductSpec> productSpecList=productSpecService.FindAllProductSpec();
      return Result.build(productSpecList,ResultCodeEnum.SUCCESS);
    }
}
